<?php
defined('_JEXEC') or die('Restricted access');
global $mainframe;
$db = & JFactory::getDBO();
$document =& JFactory::getDocument();

$document->addScript ('components/com_wrecruit/js/other_employers.js');
$model = $this->getModel('wrecruit', 'WRecruitModel');
$user	  =  & JFactory::getUser();
$uid    =$user->id;
?>
<style type="text/css">
	.job-title a {color:#333!important;font-weight:bold;text-decoration:underline;}
	.job-title a:hover {text-decoration:none;} 
	
</style>
<script language="Javascript">
function confirmdeletejob(){
        return confirm("<?php echo JText::_('JS_ARE_YOU_SURE_DELETE_THE_JOB'); ?>");
 }

function removeJobs(chk){
	var checkbox = document.getElementById('frm_emp').elements[chk];
	var items ="";
	for(var i=0;i<checkbox.length;i++) {
		if(checkbox[i].checked==true){
			items = items + checkbox[i].value+",";
			//alert("checked:"+checkbox[i].value);
		}
	}
	if(items=="" || items==null){
		alert("Pls check at least one item to delete!");
	}else {
		var answer = confirm("Are you sure to delete?")
		if (answer){
			window.location = "index.php?option=com_wrecruit&c=wrecruit&task=deletemultijobs&Itemid=<?php echo $this->Itemid; ?>&elements="+items;
		}
		else{
			//alert("Cancelled!")
		}
	}	
}
    
</script>

<?php if ($this->config['offline'] == '1'){ ?>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td valign="top" class="<?php echo $this->theme['title']; ?>"><?php echo $this->config['title']; ?>
		</td>
	</tr>
	<tr>
		<td height="25"></td>
	</tr>
	<tr>
		<td class="wrecruitmsg"><?php echo $this->config['offline_text']; ?>
		</td>
	</tr>
</table>
<?php }
else{
	if (isset($this->userrole->rolefor)){
		if ($this->userrole->rolefor == 1) // employer
		$allowed = true;
		else
		$allowed = false;
	}
	else { if ($this->config['visitorview_emp_conrolpanel'] == 1) $allowed = true; else $allowed = false; } // user not logined
	if ($allowed == true) {
		?>
<div class="box-list-job">
	<div class="job-seeker-panel">
	<?php include 'left_panel.php';?>
	</div>
	<form name="frmJob" id="frm_emp" method="post"	action="index.php">
		<div class="job-seeker-right">
			<div class="head-title">
				<h2>My Job</h2>
			</div>
			<?php if(!empty($this->myjobs)) {?>
			<div class="head-button">
			  	<div>
					<span style="cursor:pointer;" onclick="topupJobs('checked[]')"><img src="components/com_wrecruit/images/topup_job.jpg" /></span>
					<span style="cursor:pointer;" onclick="removeJobs('checked[]')"><img src="components/com_wrecruit/images/multi_remove_job.jpg" /></span>
					<span style="cursor:pointer;" onclick="renewJobs('checked[]')"><img src="components/com_wrecruit/images/renew_job.jpg" /></span>
				</div>
			</div>
			<ul class="job-list-detail">
				<li class="head-title">
					<div class="checkbox">
						<input type="checkbox" name="all" id="all" onclick="checkedAll()" />
					</div>
					<div class="job-title">
						<a href="<?php echo JURI::base()."index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=job.title&page=".JRequest::getVar('page')."&Itemid=".$this->Itemid; ?>">Title</a>
					</div>
					<div class="job-type">
						<a href="<?php echo JURI::base()."index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=cat.cat_title&page=".JRequest::getVar('page')."&Itemid=" .$this->Itemid; ?>">Type / Category</a>
					</div>
					<div class="job-date-post">
						<a href="<?php echo JURI::base()."index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=job.startpublishing&page=".JRequest::getVar('page')."&Itemid=" .$this->Itemid; ?>">Date posted</a>
					</div>
					<div class="job-date-expired">
						<a href="<?php echo JURI::base()."index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=job.stoppublishing&page=".JRequest::getVar('page')."&Itemid=" .$this->Itemid; ?>">Expired date</a>
					</div>
				</li>
				<?php foreach ($this->myjobs as $job) {?>
				<li>
					<div class="checkbox">
						<input type="checkbox" name="checked[]" value="<?php echo $job->id;?>"/>
					</div>
					<div class="job-title">
					<?php $link = JRoute::_('index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=view_job&vj=1&oi='.$job->id.'&Itemid='.$this->Itemid); ?>
                     <a href="<?php echo $link?>" class="" title="<?php echo JText::_('JS_VIEW'); ?>"><?php echo $job->title;?></a>
					</div>
					<div class="job-type">
					<?php echo $job->cat_title;?>
					</div>
					<div class="job-date-post">
					<?php echo date("d/m/Y",strtotime($job->startpublishing));?>
					</div>
					<div class="job-date-expired">
					<?php echo date("d/m/Y",strtotime($job->deadline));?>
					</div>
					<div class="link-remove">
					<?php
					$link_del = JURI::base().'index.php?option=com_wrecruit&c=wrecruit&task=deleteThisJob&bd='.$job->id.'&Itemid='.$this->Itemid;
					$link_edit =JURI::base().'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=postjob&bd='.$job->id.'&Itemid='.$this->Itemid;
					?>
						<a href="<?php echo $link_edit;?>"><img alt="edit"
							src="components/com_wrecruit/images/edit_job.png" /> </a> <a
							href="<?php echo $link_del;?>"
							onclick=" return confirmdeletejob();"
							title="<?php echo JText::_('JS_DELETE'); ?>"><img alt="edit"
							src="components/com_wrecruit/images/delete_job.png" /> </a> 
					</div>
				</li>
				<?php }?>
			</ul>
			<div class="pagination">
				<?php 
				$sql = "SELECT job.id, job.uid, job.title, cat.cat_title, job.startpublishing, job.stoppublishing, job.deadline FROM 
					".$db->nameQuote('#__wrecruit_jobs')." AS job JOIN ".$db->nameQuote('#__wrecruit_categories')." AS cat
					ON job.jobcategory=cat.id WHERE job.uid = ".$uid;
				$page = JRequest::getVar("page");
				$number_show = 5;
				if($page > 1){
					$p	=	$page;
				}
				else{
					$p	=	1;
				}
				$start	=	($p-1)*$number_show;
				$total  = $model->getTotalRows($sql);
				if($p!=1){?>
		    	<a href="index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=<?php echo JRequest::getVar('sort');?>&Itemid=<?php echo JRequest::getVar('Itemid');?>&page=<?php echo $p-1;?>">Previous</a>
		    	<?php }
					for($i=0;$i<$total;$i=$i+$number_show){
						$count++;?>
				   		 <a href="index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=<?php echo JRequest::getVar('sort');?>&Itemid=<?php echo JRequest::getVar('Itemid');?>&page=<?php echo ($i/$number_show)+1;?>"><? echo ($i/$number_show)+1;?></a><?php 
					}
					if($p!=$count){?>
				   		<a href="index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjob&sort=<?php echo JRequest::getVar('sort');?>&Itemid=<?php echo JRequest::getVar('Itemid');?>&page=<?php echo $p+1;?>">Next</a>
				<?php
					}
				?>
			</div>
			<?php }	?>
		</div>
	</form>
</div>
			<?php
	} else{ // not allowed job posting
		//Update by Vireak on 09/08/2012
		//Add frame to this warning and some styling
		//---------------------
		echo '<div class="box-list"><div class="head-title"><h2>Oop!</h2></div>';
		echo '<span class="wr_info"><p>'.JText::_('JS_YOU_ARE_NOT_ALLOWED_TO_VIEW').'</p>';
		echo '<p>This page is reserved for the authorized employers or recruiters only. </p></span>';
		echo '</div>';
		//---------------------
	}
}//ol
?>
<div width="100%">
<?php
if($this->config['fr_cr_txsh']) {
	echo
	'<table width="100%" style="table-layout:fixed;">
		<tr><td height="15"></td></tr>
		<tr><td style="vertical-align:top;" align="center">'.$this->config['fr_cr_txa'].$this->config['fr_cr_txb'].'</td></tr>
	</table>';
}
?>
</div>
